package com.mach.platform.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Administrator
 * @Description:
 * @Package: com.mach.platform.utils
 * @time 2018/8/13 0013 16:23
 */
public class Utils {

	/**
	 * 定义公共数字匹配类型
	 */
	private static Pattern NUMBER_PATTERN = Pattern.compile("[0-9]*");

	/**
	 * 利用正则表达式判断字符串是否是数字
	 * @param str
	 * @return
	 */
	public static boolean isNumeric (String str) {
		Pattern pattern = NUMBER_PATTERN;
		Matcher isNum = pattern.matcher(str);
		if (!isNum.matches()) {
			return false;
		}
		return true;
	}

	/**
	 * 字符串转化成为16进制字符串
	 *
	 * @param s
	 * @return
	 */
	public static String StrToHexString(String s) {
		String str = "";
		for (int i = 0; i < s.length(); i++) {
			int ch = (int) s.charAt(i);
			String s4 = Integer.toHexString(ch);
			str = str + s4;
		}
		return str;
	}
}
